import formJs from "./regexDetail.js"; //新增弹框配置项
import TableLyout from '@/components/commonPublic/tableLyoutDetail.vue'
import TableData from "@/components/public/el-table-pagination";
import CustomDialog from "@/components/stationProductionPage/BridgeManage/bridgeNumDetails/index.vue";

import {
    getBeamInfoLists,//列表
} from "@/api/BackStage/stationProductionPage/request.js";

export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
    ],
    data() {
        return {
            visible: "",
            title: null,
            isLock: false,
            dialogHeight: null,
            btnShow: true,
            newRow: null,
            loading: false,

            // 列表
            treelength: false,
            btnObj: formJs.btnObj, //按钮
            getList: {
                fId: "", // 左侧选中组织机构id
                page: 1, // 当前页码
                pageSize: 20, // 每页显示条数
                userId: "", // 查询待办或已办时传 列表页查询不传
            },
            table_config: formJs.table_config, //列表
            queryCriteriaData: {}, //分页
            tableData: [],
            RowData: null, //列表详情
            dataFid: null, //列表详情id
            // 列表

            // 弹框
            isShow: false, //是否显示弹框
            statusNum2: null, //点击那个按钮
            // 弹框
        };
    },
    components: {
        TableLyout,
        TableData,
        CustomDialog
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.newRow = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
        this.btnRole(this.name);
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        this.getList.fId = this.newRow.fId;
        this.yj_searchForm(this.getList);

        if (this.statusNum == 1) { //编辑
            this.btnShow = true;
        } else if (this.statusNum == 7) { //查看
            this.btnShow = false;
        }
        this.getHeight();

        this.table_config.operation.cols = [
            {
                prop: "fStatus",
                type: "primary",
                handleRow: this.handleRow,
            },
        ];
        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;
            if (rowData == "已完成") {
                color = "green !important";
            } else if (rowData == "未开始") {
                color = "red !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        edit() {
            this.closeFormData = this.$options.data.call(this).closeFormData;
        },
        // 弹框
        refreshList2() {
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        closeDialog2() {
            this.isShow = false;
        },
        // 弹框

        // 按钮
        getBtnName(name, status) {
            this.yj_edit(status);
        },
        // 按钮

        // 编辑/查看
        yj_edit(num) {
            this.statusNum2 = num;
            this.dialogTitle = "预制梁板信息";
            if (num == 1) { // 编辑
                if (this.dataFid != null) {
                    this.editText();
                } else {
                    this.$message.warning("请先选择需要编辑的数据");
                }
            } else if (num == 7) { //查看
                if (this.dataFid != null) {
                    this.isShow = true;
                    this.editText();
                } else {
                    this.$message.warning("请先选择需要查看的数据");
                }
            }
        },
        editText() {//列表数据
            this.isShow = true;
        },
        // 点击查看
        yj_viewForm(row, label) {
            this.RowData = row;
            this.dataFid = row.fId;
            if (label == "梁号") {
                this.yj_edit(7);
            }
            return row, label;
        },
        // 点击当前行
        rowChange(val) {
            this.RowData = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                fId: data.fId, //左侧选中组织机构id
                page: data.page, //当前页码
                pageSize: 20, //每页显示条数
                userId: this.userInfo.userId, //查询待办或已办时传 列表页查询不传
            }
            this.loading = true;
            var that = this;
            getBeamInfoLists(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.precastBeamInfoLists.list;
                        that.queryCriteriaData = res.data.precastBeamInfoLists;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },

        // 保存
        yj_saveForm() {
            this.$emit("close");
        },
       
        // 保存

    },
};